<template>
  <el-row :gutter="20">
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">左侧占位</el-col>
    <el-col :xs="24" :sm="20">
      <el-card style="background-color: rgba(255,255,255,0.9)" class="categories-card">
        <div slot="header" class="total">
          <div class="titleIndex">
            <i class="el-icon-collection"></i>
            <span>全部分类</span>
          </div>
        </div>
        <div class="categories-container">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="category in categoryList" :key="category.id" class="category-item">
              <el-card shadow="hover" @click.native="goToCategory(category.id)" class="category-card">
                <div class="category-icon">
                  <el-image 
                    :src="category.icon" 
                    fit="cover"
                    style="width: 60px; height: 60px; border-radius: 50%;"
                  >
                    <div slot="error" class="image-slot">
                      <i class="el-icon-collection" style="font-size: 40px; color: #409eff;"></i>
                    </div>
                  </el-image>
                </div>
                <div class="category-info">
                  <h3>{{ category.name }}</h3>
                  <p class="category-desc">{{ category.description }}</p>
                  <div class="category-meta">
                    <span class="blog-count">{{ category.blogCount }} 篇文章</span>
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>
      </el-card>
    </el-col>
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">右侧占位</el-col>
  </el-row>
</template>

<script>
export default {
  name: 'Categories',
  data() {
    return {
      categoryList: [
        {
          id: 1,
          name: '前端开发',
          description: 'Vue、React、JavaScript等前端技术文章',
          icon: 'https://via.placeholder.com/60',
          blogCount: 25
        },
        {
          id: 2,
          name: '后端开发',
          description: 'Java、Spring、数据库等后端技术',
          icon: 'https://via.placeholder.com/60',
          blogCount: 18
        },
        {
          id: 3,
          name: '算法与数据结构',
          description: '算法学习、数据结构、编程题解',
          icon: 'https://via.placeholder.com/60',
          blogCount: 32
        },
        {
          id: 4,
          name: '开发工具',
          description: 'IDE、Git、Docker等开发工具使用',
          icon: 'https://via.placeholder.com/60',
          blogCount: 15
        },
        {
          id: 5,
          name: '生活随笔',
          description: '日常生活、读书笔记、感悟分享',
          icon: 'https://via.placeholder.com/60',
          blogCount: 20
        },
        {
          id: 6,
          name: '技术分享',
          description: '技术总结、经验分享、最佳实践',
          icon: 'https://via.placeholder.com/60',
          blogCount: 28
        },
        {
          id: 7,
          name: '学习笔记',
          description: '学习过程中的笔记和总结',
          icon: 'https://via.placeholder.com/60',
          blogCount: 22
        },
        {
          id: 8,
          name: '项目实践',
          description: '实际项目开发经验分享',
          icon: 'https://via.placeholder.com/60',
          blogCount: 16
        }
      ]
    }
  },
  methods: {
    goToCategory(id) {
      this.$router.push({
        path: '/',
        query: { typeId: id }
      })
    }
  }
}
</script>

<style scoped>
.categories-card {
  margin-top: 20px;
}

.titleIndex {
  display: flex;
  align-items: center;
  font-size: larger;
  font-weight: bold;
}

.titleIndex i {
  margin-right: 10px;
  color: #409eff;
  font-size: 20px;
}

.categories-container {
  padding: 20px 0;
}

.category-item {
  margin-bottom: 20px;
}

.category-card {
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
  height: 100%;
}

.category-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.category-icon {
  margin-bottom: 15px;
  display: flex;
  justify-content: center;
}

.category-info h3 {
  margin: 10px 0;
  color: #303133;
  font-size: 18px;
}

.category-desc {
  color: #909399;
  font-size: 14px;
  margin: 10px 0;
  min-height: 40px;
}

.category-meta {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #ebeef5;
}

.blog-count {
  color: #409eff;
  font-size: 14px;
  font-weight: bold;
}

.image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 60px;
  height: 60px;
  background: #f5f7fa;
  border-radius: 50%;
}

@media screen and (max-width: 768px) {
  .categories-container {
    padding: 10px 0;
  }
  
  .category-item {
    margin-bottom: 15px;
  }
}
</style>

